using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
//
// DotNetNuke?- http://www.dotnetnuke.com
// Copyright (c) 2002-2009
// by DotNetNuke Corporation
//

using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Users;

namespace DotNetNuke.Security.Permissions
{

    public partial class WorkflowStatePermissionController
    {

        #region "Private Shared Methods"

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ClearPermissionCache clears the WorkflowState Permission Cache
        /// </summary>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        private static void ClearPermissionCache()
        {
            DataCache.RemoveCache(WorkflowStatePermissionCacheKey);
        }

        #endregion

        #region "Public Shared Methods"

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// AddWorkflowStatePermission adds a WorkflowState Permission to the Database
        /// </summary>
        /// <param name="objWorkflowStatePermission">The WorkflowState Permission to add</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public static int AddWorkflowStatePermission(WorkflowStatePermissionInfo objWorkflowStatePermission)
        {
            int Id = provider.AddWorkflowStatePermission(objWorkflowStatePermission.StateID, objWorkflowStatePermission.PermissionID, objWorkflowStatePermission.RoleID, objWorkflowStatePermission.AllowAccess, objWorkflowStatePermission.UserID, UserController.GetCurrentUserInfo().UserID);
            ClearPermissionCache();
            return Id;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// DeleteWorkflowStatePermission deletes a WorkflowState Permission in the Database
        /// </summary>
        /// <param name="WorkflowStatePermissionID">The ID of the WorkflowState Permission to delete</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public static void DeleteWorkflowStatePermission(int WorkflowStatePermissionID)
        {
            provider.DeleteWorkflowStatePermission(WorkflowStatePermissionID);
            ClearPermissionCache();
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// DeleteWorkflowStatePermissionsByStateID deletes a WorkflowState's 
        /// WorkflowState Permission in the Database
        /// </summary>
        /// <param name="StateID">The ID of the State to delete</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public static void DeleteWorkflowStatePermissionsByStateID(int StateID)
        {
            provider.DeleteWorkflowStatePermissionsByStateID(StateID);
            ClearPermissionCache();
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// DeleteWorkflowStatePermissionsByUserID deletes a user's WorkflowState Permission in the Database
        /// </summary>
        /// <param name="objUser">The user</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public static void DeleteWorkflowStatePermissionsByUserID(UserInfo objUser)
        {
            provider.DeleteWorkflowStatePermissionsByUserID(objUser.UserID);
            ClearPermissionCache();
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetWorkflowStatePermission gets a WorkflowState Permission from the Database
        /// </summary>
        /// <param name="WorkflowStatePermissionID">The ID of the WorkflowState Permission</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public static WorkflowStatePermissionInfo GetWorkflowStatePermission(int WorkflowStatePermissionID)
        {
            return CBO.FillObject<WorkflowStatePermissionInfo>(provider.GetWorkflowStatePermission(WorkflowStatePermissionID), true);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// UpdateWorkflowStatePermission updates a WorkflowState Permission in the Database
        /// </summary>
        /// <param name="objWorkflowStatePermission">The WorkflowState Permission to update</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public static void UpdateWorkflowStatePermission(WorkflowStatePermissionInfo objWorkflowStatePermission)
        {
            provider.UpdateWorkflowStatePermission(objWorkflowStatePermission.WorkflowStatePermissionID, objWorkflowStatePermission.StateID, objWorkflowStatePermission.PermissionID, objWorkflowStatePermission.RoleID, objWorkflowStatePermission.AllowAccess, objWorkflowStatePermission.UserID, UserController.GetCurrentUserInfo().UserID);
            ClearPermissionCache();
        }


        public static ArrayList GetPermissionsByStateID(int StateID)
        {
            return CBO.FillCollection(provider.GetPermissionsByStateID(StateID), typeof(PermissionInfo));
        }

        #endregion

    }



}
